package com.xianggu.designMode.iterationMethod.demo1;

import java.util.Iterator;

/**
 * @author chengjy
 * @date 2025/3/19
 */
 class User implements Iterable<User>{

     private String name;
     private int age;

    public User(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public int getAge() {
        return age;
    }

    @Override
    public String toString() {
        return "User{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    /**
     * Returns an iterator over elements of type {@code T}.
     *
     * @return an Iterator.
     */
    @Override
    public Iterator<User> iterator() {
        return new UserIterator();
    }

    class UserIterator implements Iterator<User>{

        /**
         * Returns {@code true} if the iteration has more elements.
         * (In other words, returns {@code true} if {@link #next} would
         * return an element rather than throwing an exception.)
         *
         * @return {@code true} if the iteration has more elements
         */
        @Override
        public boolean hasNext() {
            return false;
        }

        /**
         * Returns the next element in the iteration
         * @return the next element in the iteration
         */
        @Override
        public User next() {
            return null;
        }

    }
}
